package interfaz;


import gestores.GestorUsuario;

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridBagLayout;
import java.awt.Toolkit;

import javax.swing.JLabel;
import java.awt.GridBagConstraints;
import javax.swing.JTextField;
import java.awt.Insets;
import javax.swing.JButton;

import componentes.Usuario;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class PantallaInicialUserReg extends JPanel {
	private JTextField usuarioLogueado;
	private JPanel panelSuperiorUser;
	private JLabel lblUsuario;
	private JButton btnSalir;
	private JPanel panelOpUserReg;
	private JLabel lblComoUsuarioUsted;
	private JButton btnListarCompetencias;
	private JButton btnListarLugaresDe;
	private JButton btnModificarDatos;
	

	/**
	 * Create the panel.
	 * 
	 * @param usuarioLogueado2
	 * @param panelLLamador
	 */
	public PantallaInicialUserReg(JPanel panelPantallaInicial, Usuario instUserLog) {

		
		panelSuperiorUser = new JPanel();
		lblUsuario = new JLabel("Usuario:");
		usuarioLogueado = new JTextField();
		btnSalir = new JButton("Salir");

		panelOpUserReg = new JPanel();

		lblComoUsuarioUsted = new JLabel("Como usuario usted puede:");
		btnListarCompetencias = new JButton("        Listar Competencias      ");
		btnListarLugaresDe = new JButton("Listar Lugares De Realizacion");
		btnModificarDatos = new JButton("           Modificar Datos           ");

		incializarInterfaz(panelPantallaInicial, instUserLog, this);

	}

	private void incializarInterfaz(final JPanel panelPantallaInicial ,final Usuario instUserLog, final PantallaInicialUserReg panelUsuarioRegistrado) {
			
		setLayout(new BorderLayout(0, 0));

		panelSuperiorUser.setBackground(new Color(173, 69, 0));
		add(panelSuperiorUser, BorderLayout.NORTH);
		GridBagLayout gbl_panelSuperiorUser = new GridBagLayout();
		gbl_panelSuperiorUser.columnWidths = new int[] { 319, 0, 0, 0 };
		gbl_panelSuperiorUser.rowHeights = new int[] { 0, 0 };
		gbl_panelSuperiorUser.columnWeights = new double[] { 0.0, 0.0, 0.0, Double.MIN_VALUE };
		gbl_panelSuperiorUser.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
		panelSuperiorUser.setLayout(gbl_panelSuperiorUser);

		GridBagConstraints gbc_lblUsuario = new GridBagConstraints();
		gbc_lblUsuario.weightx = 1.0;
		gbc_lblUsuario.insets = new Insets(0, 0, 0, 5);
		gbc_lblUsuario.anchor = GridBagConstraints.EAST;
		gbc_lblUsuario.gridx = 0;
		gbc_lblUsuario.gridy = 0;
		panelSuperiorUser.add(lblUsuario, gbc_lblUsuario);

		
		usuarioLogueado.setBackground(new Color(173, 69, 0));
		GridBagConstraints gbc_textField = new GridBagConstraints();
		gbc_textField.insets = new Insets(0, 0, 0, 5);
		gbc_textField.fill = GridBagConstraints.HORIZONTAL;
		gbc_textField.gridx = 1;
		gbc_textField.gridy = 0;
		panelSuperiorUser.add(usuarioLogueado, gbc_textField);
		usuarioLogueado.setText(GestorUsuario.getInstance().getName(instUserLog));
		usuarioLogueado.setBorder(null);
		usuarioLogueado.setEditable(false);
		

		GridBagConstraints gbc_btnSalir = new GridBagConstraints();
		gbc_btnSalir.gridx = 2;
		gbc_btnSalir.gridy = 0;
		panelSuperiorUser.add(btnSalir, gbc_btnSalir);
		
		
		// Finaliza el panel sup. comienza el de opciones

		panelOpUserReg.setBackground(new Color(236, 141, 4));
		add(panelOpUserReg, BorderLayout.CENTER);

		GridBagConstraints gbc_lblComoUsuarioUsted = new GridBagConstraints();
		gbc_lblComoUsuarioUsted.gridwidth = 3;
		gbc_lblComoUsuarioUsted.anchor = GridBagConstraints.WEST;
		gbc_lblComoUsuarioUsted.insets = new Insets(10, 30, 5, 5);
		gbc_lblComoUsuarioUsted.gridx = 0;
		gbc_lblComoUsuarioUsted.gridy = 0;
		panelOpUserReg.add(lblComoUsuarioUsted, gbc_lblComoUsuarioUsted);

		GridBagLayout gbl_panelOpUserReg = new GridBagLayout();
		gbl_panelOpUserReg.columnWidths = new int[] { 0, 217, 100, 0 };
		gbl_panelOpUserReg.rowHeights = new int[] { 0, 0, 0, 0, 0 };
		gbl_panelOpUserReg.columnWeights = new double[] { 0.0, 0.0, 0.0,
				Double.MIN_VALUE };
		gbl_panelOpUserReg.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0,
				Double.MIN_VALUE };
		panelOpUserReg.setLayout(gbl_panelOpUserReg);

		GridBagConstraints gbc_btnListarCompetencias = new GridBagConstraints();
		gbc_btnListarCompetencias.weightx = 1.0;
		gbc_btnListarCompetencias.anchor = GridBagConstraints.SOUTH;
		gbc_btnListarCompetencias.weighty = 0.5;
		gbc_btnListarCompetencias.insets = new Insets(10, 0, 10, 5);
		gbc_btnListarCompetencias.gridx = 1;
		gbc_btnListarCompetencias.gridy = 1;
		panelOpUserReg.add(btnListarCompetencias, gbc_btnListarCompetencias);

		GridBagConstraints gbc_btnListarLugaresDe = new GridBagConstraints();
		gbc_btnListarLugaresDe.weightx = 1.0;
		gbc_btnListarLugaresDe.weighty = 0.5;
		gbc_btnListarLugaresDe.insets = new Insets(10, 0, 10, 5);
		gbc_btnListarLugaresDe.gridx = 1;
		gbc_btnListarLugaresDe.gridy = 2;
		panelOpUserReg.add(btnListarLugaresDe, gbc_btnListarLugaresDe);

		GridBagConstraints gbc_btnModificarDatos = new GridBagConstraints();
		gbc_btnModificarDatos.weightx = 1.0;
		gbc_btnModificarDatos.anchor = GridBagConstraints.NORTH;
		gbc_btnModificarDatos.weighty = 1.0;
		gbc_btnModificarDatos.insets = new Insets(10, 0, 10, 5);
		gbc_btnModificarDatos.gridx = 1;
		gbc_btnModificarDatos.gridy = 3;
		panelOpUserReg.add(btnModificarDatos, gbc_btnModificarDatos);

		// Listeners
		
		btnListarCompetencias.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JPanel listarCompDep = new ListarCompetenciasDeportivas(panelOpUserReg, instUserLog, panelUsuarioRegistrado);
				listarCompDep.setVisible(true);
				panelOpUserReg.setVisible(false);
				add(listarCompDep, BorderLayout.CENTER);
			}
		});

		btnListarLugaresDe.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Toolkit.getDefaultToolkit().beep();
				JOptionPane.showMessageDialog(null, "Funcionalidad no implementada", "Aviso", JOptionPane.INFORMATION_MESSAGE);
			}
		});
		
		btnModificarDatos.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Toolkit.getDefaultToolkit().beep();
				JOptionPane.showMessageDialog(null, "Funcionalidad no implementada", "Aviso", JOptionPane.INFORMATION_MESSAGE);
			}
		});
	
		
		
		btnSalir.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				setVisible(false);
				panelPantallaInicial.setVisible(true);

			}
		});

	}

}
